package com.intelligent.ispc.utils;

import com.intelligent.ispc.core.entity.TestData;

import java.util.Comparator;
import java.util.Date;

/**
 * Created by julia on 16/3/2.
 */
public class ComparatorTestData implements Comparator {
    @Override
    public int compare(Object o1, Object o2) {
        TestData testData1 =(TestData)o1;
        TestData testData2 =(TestData)o2;

        String serialNumber1 = testData1.getTestData().get(TestData.PSA_SERIAL_NUMBER).toString();
        String serialNumber2 = testData2.getTestData().get(TestData.PSA_SERIAL_NUMBER).toString();

        Date startTime1 = (Date) testData1.getTestData().get(TestData.PSA_START_TIME);
        Date startTime2 = (Date) testData2.getTestData().get(TestData.PSA_START_TIME);

        int flag = serialNumber1.compareTo(serialNumber2);
        if(flag==0){
            if (startTime1 == null || startTime2 == null) {
                return flag;
            }
            return startTime1.compareTo(startTime2);
        }else{
            return flag;
        }
    }
}
